<template>
  <div>
    <!--      end-->
    <div class="mb-10">
      <div class="toplineBox">
        <div class="toplineBox-left">
          <el-button @click="groupId=0,groupVisible=true" size="small">添加群组</el-button>
        </div>
        <p class="numberline toplineBox-right">总{{ page.total }}条</p>
      </div>
    </div>
    <!--本体列表，数据 -->
    <div class="table-body">
      <div class="table-body-box">
        <el-table
            border
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              prop="id"
              label="ID"
              width="90"
              align="center">
          </el-table-column>
          <el-table-column
              align="center"
              prop="name"
              label="群组名称"
              width="110">
          </el-table-column>
          <el-table-column
              align="center"
              label="群组人员">
            <template slot-scope="scope">
              <el-tag v-for="item in scope.row.user_ids" class="mr-5">{{item.realname}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
              label="操作"
              width="180"
              align="center">
            <template slot-scope="scope">
              <el-button size="small" @click="handleEdit(scope.row.id)">编辑</el-button>
              <el-button size="small" @click="detelTearch(scope.row)" type="danger" plain>删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!--工具条 分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination
          background
          layout="total, prev, pager, next"
          :current-page="page.pageindex"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
      </el-pagination>
    </el-col>
    <groupAdd :visible.sync="groupVisible" :groupId="groupId" @InitFn="InitFn"></groupAdd>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import {mapGetters} from "vuex";
import groupAdd from "./groupAdd";
import {groupIndex, groupDelete} from "@/api/admin/group"

export default {
  components: {
    groupAdd
  },
  data() {
    return {
      groupVisible: false,
      groupId: 0,
      // 设置table样式
      tableStyle: tableoption,
      tearchVisible: false,
      dialogVisible: false,
      arryList: [], // 数据列表
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      handleSelection: [],
      // new
      eidtOption: null,
      checkType: null,
      tearchOption: '',
      // 搜索组件
      searchForm: {},
      tearchEditVisible: false,
      historyVisible: false,
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn() {
      this.searchForm.p = this.page.pageindex
      groupIndex(this.searchForm).then(res=>{
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    // 分页
    handleSizeChange(val) {
      this.arryList = []
      this.page.pageindex = val
      this.InitFn()
    },
    handleSelectionChange(val) {
      console.log('选择框选择变化', val) // 所有选中值
      this.handleSelection = val
    },
    detelTearch(option) {
      let n = this
      this.$confirm('确认删除群组-' + option.name + ', 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        groupDelete({id: option.id}).then(res=>{
          n.InitFn()
        })
      }).catch(() => {
      })
    },

    // 编辑教职工
    handleEdit(id) {
      this.groupId = id
      this.groupVisible = true
    }
  },
  mounted() {
  }
}
</script>
<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}
</style>
<!--<div class="wx-user-box">-->
<!--<span>{{scope.row.openid?'已绑定':''}}</span>-->
<!--<span v-if="scope.row.openid" class="wx-user-box-line">-->
<!--                    <img :src="scope.row.wx.pic" alt="" width="30" height="30">{{scope.row.wx.user_name}}-->
<!--                  </span>-->
<!--</div>-->
